{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6]\n",
      "[[1 2 3 4 5]\n",
      " [9 8 7 6 5]]\n",
      "(6,) (2, 5)\n",
      "[[0. 0. 0.]\n",
      " [0. 0. 0.]] \n",
      " [[1. 1.]\n",
      " [1. 1.]]\n",
      "[[  1   2   3   4   5]\n",
      " [100   8   7   6   5]]\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "# numpy 操作矩阵的 CRUD\n",
    "import numpy as np\n",
    "data1 = np.array([1,2,3,4,5,6])\n",
    "print(data1)\n",
    "data2 = np.array([[1,2,3,4,5],\n",
    "                  [9,8,7,6,5]])\n",
    "print(data2)\n",
    "## 维度\n",
    "print(data1.shape, data2.shape)\n",
    "print(np.zeros([2,3]),'\\n',np.ones([2,2]))\n",
    "\n",
    "##改查\n",
    "data2[1,0] = 100\n",
    "print(data2)\n",
    "print(data2[0,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2. 2. 2.]\n",
      " [2. 2. 2.]]\n",
      "[[0.33333333 0.33333333 0.33333333]\n",
      " [0.33333333 0.33333333 0.33333333]]\n",
      "[[3. 3. 3.]\n",
      " [3. 3. 3.]]\n",
      "[[1. 1. 1.]\n",
      " [1. 1. 1.]] \n",
      " [[1 2 3]\n",
      " [4 5 6]]\n",
      "加法：\n",
      " [[2. 3. 4.]\n",
      " [5. 6. 7.]]\n",
      "\n",
      "乘法：\n",
      " [[1. 2. 3.]\n",
      " [4. 5. 6.]]\n"
     ]
    }
   ],
   "source": [
    "##基本运算\n",
    "data3 = np.ones([2,3])\n",
    "print(data3*2)    # 对应相乘\n",
    "print(data3/3)\n",
    "print(data3+2)\n",
    "\n",
    "## 矩阵+*\n",
    "data4 = np.array([[1,2,3],[4,5,6]])\n",
    "print(data3,'\\n',data4)\n",
    "print('加法：\\n',data3+data4)\n",
    "print('\\n乘法：\\n',data3*data4)   ##对应相乘"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
